﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SRM.DataObjects;
using System.Data;

namespace SRM
{
    public partial class RegisterAccountForm : System.Web.UI.Page
    {
        public DataTable Applicant { get; set; }
        public string ApplicantKey { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            ErrorMessage_Literal.Text = string.Empty;
            SuccessMessage_Literal.Text = string.Empty;

            #region comment - to be delete
            
            //this.hdn_UseSAPCode.Value = "1";
            //// this.hdn_applicantKey.Value = "550"; // test language
            //this.hdn_applicantKey.Value = "765"; // test professional membership
            //this.ApplicantKey = "6814";

            //Help.Decrypt("asd");

            //// 8636
            //// 6814
            //this.Applicant = SRM_Applicant.GetApplicant(6814);
            #endregion comment - to be delete
        } // protected void Page_Load(object sender, EventArgs e)

        protected void Register_Button_Click(object sender, EventArgs e)
        {
            // Create Account

            DataTable applicantDataTable = SRM_Applicant.GetApplicantByEmail(Email_TextBox.Text.Trim());
            if (applicantDataTable.Rows.Count > 0)
            {
                ErrorMessage_Literal.Text = "This account exist in our system.";
            }
            else
            {
                SRM_Applicant.AddApplicant(Email_TextBox.Text.Trim(), Password_TextBox.Text.Trim());
                if (Request.QueryString.Count > 0)
                {
                    SuccessMessage_Literal.Text =
                        string.Format("Account created. Please <a href='LoginForm.aspx?{0}'>login</a> using the account that you have created.", Request.QueryString);
                }
                else
                {
                    SuccessMessage_Literal.Text =
                        string.Format("<a href='LoginForm.aspx'>here</a>");
                }
                // "LoginForm.aspx<%= Request.QueryString.Count > 0 ? "?" + Request.QueryString : String.Empty %>
                //"Account created. Please login using the account that you have created.";
            }
            

            // Fetch record in database
            //DataTable dtApplicantAccount = SRM_Applicant.GetApplicantAccount(Email_TextBox.Text.Trim());
            //if ((dtApplicantAccount != null) && (dtApplicantAccount.Rows.Count > 0))
            //{
            //    // Compare MD5
            //}
            //else
            //{
            //    // Display error message
            //    ErrorMessage_Literal.Text = "Invalid credentials.";
            //}

        } // protected void Register_Button_Click(object sender, EventArgs e)
    } // public partial class ApplicantForm : System.Web.UI.Page
} // namespace SRM